/* Copyright (c) 2015,2016 Lucky Byte, Inc.
 */
package com.lucky_byte.pay.jar.lualib;

import java.util.UUID;

import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.LibFunction;

import com.lucky_byte.pay.jar.Packet;

/**
 * 请求交易
 */
public class LuaRequest extends LibFunction
{
	private UUID uuid;
	private int uuid_no;
	private Packet packet;

	public LuaRequest(Packet packet) {
		this.uuid = UUID.randomUUID();
		this.uuid_no = 1;
		this.packet = packet;
	}

	public UUID getUUID() {
		return this.uuid;
	}

	public int getUUIDNo() {
		return uuid_no;
	}

	@Override
	public LuaValue call(LuaValue modname, LuaValue env) {
		LuaValue library = tableOf();
		env.set("reqt", library);

		library.set("uuid", this.uuid.toString());
		library.set("uuid_no", uuid_no);
		library.set("packet", new LuaPacket(packet).call());

		return library;
	}

}
